package units;

import java.util.Random;


//position @ Array
// Archer // Short // Long // 2-Hand // Spear // Hallberdier // Hoplit // Ballista // Siege - Ram // Catapult // Trebuchet // Tower



public class UnitSet {

	private int archers = 0;
	private int shortSwordsmen = 0;	
	private int longSwordsmen = 0;
	private int twohandedswordman = 0;
	private int spearman = 0;
	private int halberdier = 0;
	private int hoplit = 0;
	private int ballista = 0;
	private int siegeram = 0;
	private int catapult = 0;
	private int trebuchet = 0;
	private int tower = 0;
	
	public static final boolean[] unitTypesAll = {true,true,true,true,true,true,true,true,true,true,true,true };
	public static final boolean[][] unitTypesOnlyOne = {{true,false,false,false,false,false,false,false,false,false,false,false},
														{false,true,false,false,false,false,false,false,false,false,false,false},
														{false,false,true,false,false,false,false,false,false,false,false,false},
														{false,false,false,true,false,false,false,false,false,false,false,false},
														{false,false,false,false,true,false,false,false,false,false,false,false},
														{false,false,false,false,false,true,false,false,false,false,false,false},
														{false,false,false,false,false,false,true,false,false,false,false,false},
														{false,false,false,false,false,false,false,true,false,false,false,false},
														{false,false,false,false,false,false,false,false,true,false,false,false},
														{false,false,false,false,false,false,false,false,false,true,false,false},
														{false,false,false,false,false,false,false,false,false,false,true,false},
														{false,false,false,false,false,false,false,false,false,false,false,true}};
	
	
	
	//*********************************************
	//GETTER/SETTER:
	public int getLongSwordsmen() {
		return longSwordsmen;
	}
	public void setLongSwordsmen(int longSwordsmen) {
		this.longSwordsmen = longSwordsmen;
	}
	public int getShortSwordsmen() {
		return shortSwordsmen;
	}
	public void setShortSwordsmen(int shortSwordsmen) {
		this.shortSwordsmen = shortSwordsmen;
	}
	public int getArchers() {
		return archers;
	}
	public void setArchers(int archers) {
		this.archers = archers;
	}
	public int getBallista() {
		return ballista;
	}
	public void setBallista(int ballista) {
		this.ballista = ballista;
	}
	public int getCatapult() {
		return catapult;
	}
	public void setCatapult(int catapult) {
		this.catapult = catapult;
	}
	public int getTrebuchet() {
		return trebuchet;
	}
	public void setTrebuchet(int trebuchet) {
		this.trebuchet = trebuchet;
	}
	
	public int getTwohandedswordman() {
		return twohandedswordman;
	}
	public void setTwohandedswordman(int twohandedswordman) {
		this.twohandedswordman = twohandedswordman;
	}
	public int getSpearman() {
		return spearman;
	}
	public void setSpearman(int spearman) {
		this.spearman = spearman;
	}
	public int getHalberdier() {
		return halberdier;
	}
	public void setHalberdier(int halberdier) {
		this.halberdier = halberdier;
	}
	public int getHoplit() {
		return hoplit;
	}
	public void setHoplit(int hoplit) {
		this.hoplit = hoplit;
	}
	public int getSiegeram() {
		return siegeram;
	}
	public void setSiegeram(int siegeram) {
		this.siegeram = siegeram;
	}
	public int getTower() {
		return tower;
	}
	public void setTower(int tower) {
		this.tower = tower;
	}
	
	
	//*********************************************
	

	
	
	public UnitSet() {}
	public UnitSet(int archers, int shortSwordsmen, int longSwordsmen, int twohandedswordman, int spearman, int halberdier, int hoplit,  int ballista, int siegeram,  int catapult, int trebuchet,int tower) {
		this.archers = archers;
		this.shortSwordsmen = shortSwordsmen;	
		this.longSwordsmen = longSwordsmen;
		this.twohandedswordman = twohandedswordman;
		this.spearman = spearman;
		this.halberdier = halberdier;
		this.hoplit = hoplit;
		this.ballista = ballista;
		this.siegeram = siegeram;
		this.catapult = catapult;
		this.trebuchet = trebuchet;
		this.tower = tower;

	}
	
	//--
	
	public String toLongString() {
		return 	archers + " Archers, " +
		shortSwordsmen + " Short - Swordman, " +
		longSwordsmen + " Long - Swordman, " +
		twohandedswordman + " Two Handen - Swordman, " +
		spearman + " Spearman, " +
		halberdier + " Halberdier, " +
		hoplit + " Hoplit, " +
		ballista + " Ballista, " +
		siegeram + " Siegeram, " +
		catapult + " Catapult, " +
		trebuchet + " Trebuchet, " +
		tower + " Tower"; 
	}
	

	public String toString() {
		String str = "";
		if (archers!=0) str =+	archers + " Archers, " ;
		if (shortSwordsmen!=0) str =+ shortSwordsmen + " Short - Swordman, ";
		if (longSwordsmen!=0) str =+longSwordsmen + " Long - Swordman, ";
		if (twohandedswordman!=0) str =+twohandedswordman + " Two Handen - Swordman, ";
		if (spearman!=0) str =+spearman + " Spearman, ";
		if (halberdier!=0) str =+halberdier + " Halberdier, ";
		if (hoplit!=0) str =+hoplit + " Hoplit, ";
		if (ballista!=0) str =+ballista + " Ballista, ";
		if (siegeram!=0) str =+siegeram + " Siegeram, ";
		if (catapult!=0) str =+catapult + " Catapult, ";
		if (trebuchet!=0) str =+trebuchet + " Trebuchet, ";
		if (tower!=0) str =+tower + " Tower, "; 
		if (!str.equals("")) {
			str = str.substring(0, str.length()-2);
		}
		return str;
	}
	
	

	// Neue Einheiten hier nicht Implementier 
	public void setRandom(int max, boolean[] useUnits) {
		Random ra = new Random();
		if (useUnits.length!=6) return;
		if (useUnits[0]) longSwordsmen =  ra.nextInt(max);
		if (useUnits[1]) shortSwordsmen = ra.nextInt(max);
		if (useUnits[2]) archers = ra.nextInt(max);
		if (useUnits[3]) ballista = ra.nextInt(max);
		if (useUnits[4]) catapult = ra.nextInt(max);
		if (useUnits[5]) trebuchet = ra.nextInt(max);
	}
	
	// Neue Einheiten hier nicht Implementier 
	public void increaseRandom(int maxGrowth, boolean[] useUnits) {
		Random ra = new Random();
		if (useUnits.length!=6) return;
		if (useUnits[0]) longSwordsmen = longSwordsmen + ra.nextInt(maxGrowth);
		if (useUnits[1]) shortSwordsmen = shortSwordsmen + ra.nextInt(maxGrowth);
		if (useUnits[2]) archers = archers + ra.nextInt(maxGrowth);
		if (useUnits[3]) ballista = ballista + ra.nextInt(maxGrowth);
		if (useUnits[4]) catapult = catapult + ra.nextInt(maxGrowth);
		if (useUnits[5]) trebuchet = trebuchet + ra.nextInt(maxGrowth);
		//System.out.println("GROWTH -> " + this.toString());
	}
	
	// Neue Einheiten hier nicht Implementier 
	public void decreaseRandom(int maxGrowth, boolean[] useUnits) {
		Random ra = new Random();
		if (useUnits.length!=6) return;
		if (useUnits[0]) longSwordsmen = longSwordsmen - ra.nextInt(maxGrowth);
		if (longSwordsmen < 0) longSwordsmen = 0;
		if (useUnits[1]) shortSwordsmen = shortSwordsmen - ra.nextInt(maxGrowth);
		if (shortSwordsmen < 0) shortSwordsmen = 0;
		if (useUnits[2]) archers = archers - ra.nextInt(maxGrowth);
		if (archers < 0) archers = 0;
		if (useUnits[3]) ballista = ballista - ra.nextInt(maxGrowth);
		if (ballista < 0) ballista = 0;
		if (useUnits[4]) catapult = catapult - ra.nextInt(maxGrowth);
		if (catapult < 0) catapult = 0;
		if (useUnits[5]) trebuchet = trebuchet - ra.nextInt(maxGrowth);
		if (trebuchet < 0) trebuchet = 0;
	}
	
	// Neue Einheiten hier nicht Implementier 
	public UnitGroup makeUnitGroup() {
		UnitGroup g = new UnitGroup();
		if (archers!=0){g.addArchers(archers);}		
		if (shortSwordsmen!=0){g.addShortSwordsmen(shortSwordsmen);}		
		if (longSwordsmen!=0){g.addLongSwordsmen(longSwordsmen);}
		if (twohandedswordman!=0) {g.addTwoHandedSwordman(twohandedswordman);}
		if (spearman!=0) {g.addSpearman(spearman);}
		if (halberdier!=0) {g.addHalberdier(halberdier);}
		if (hoplit!=0) {g.addHoplit(hoplit);}
		if (ballista!=0){g.addBallista(ballista);}
		if (siegeram!=0) {g.addSiegeRam(siegeram);}
		if (catapult!=0){g.addCatapult(catapult);}
		if (trebuchet!=0){g.addTrebuchet(trebuchet);}
		if (tower!=0) {g.addTower(tower);}
		return g;
	}
	
	// Neue Einheiten hier nicht Implementier 
	public int getSum() {
		return longSwordsmen + shortSwordsmen + archers + ballista + catapult + trebuchet;
	}
	
	// Neue Einheiten hier nicht Implementier 
	public static String unitTypesToString(boolean[] unitTypes) {
		String tmp = "";
		if (unitTypes[0]) tmp = tmp + "L ";
		if (unitTypes[1]) tmp = tmp + "S ";
		if (unitTypes[2]) tmp = tmp + "A ";
		if (unitTypes[3]) tmp = tmp + "B ";
		if (unitTypes[4]) tmp = tmp + "C ";
		if (unitTypes[5]) tmp = tmp + "T ";
		return tmp;
	}
	public void addUnit(AbstractUnit u) {
		if (u instanceof Archer){ 
			this.archers++; 
		} else if (u instanceof ShortSwordsman) {
			this.shortSwordsmen++;
		} else if (u instanceof LongSwordsman) {
			this.longSwordsmen++;
		} else if (u instanceof TwoHandedSwordman) {
			this.twohandedswordman++;
		} else if (u instanceof Spearman) {
			this.spearman++;
		} else if (u instanceof Halberdier) {
			this.halberdier++;
		} else if (u instanceof Hoplit) {
			this.hoplit++;
		} else if (u instanceof Ballista) {
			this.ballista++;
		} else if (u instanceof SiegeRam) {
			this.siegeram++;
		} else if (u instanceof Catapult) {
			this.catapult++;
		} else if (u instanceof Trebuchet) {
			this.trebuchet++;
		} else if (u instanceof Tower) {
			this.tower++;
	}
		
	}
	
}
